package com.joinway.framework.core.groovy

import com.joinway.framework.core.java.JavaBean;
import com.joinway.framework.core.java.JavaDomain;

import groovy.transform.Sortable
import groovy.util.logging.Slf4j

@Sortable
@Slf4j
class GroovyTest {

	public String name
	
	String field;
	static String x;
	
	static main(args) {
		test13()
		
//		println test9(1)
//		println test9(2)
//		
//		def i = test9(1)
//		def (j) = test9(2)
//		println i
//		println j
//		String[] arr = ['a', 'b', 'c']
	}

	static void test0(){
		String[] arr = ['a', 'b', 'c']
		println arr
		List list = arr as List
		println list
		println list.class
		
		println arr.find(){it.equals('a')}
		
		def c = {a, b -> println "$a - $b"}
		def d = 'abc'
		c('1', '2')
		
		Integer i = 0
		int j = 1
		println i.class == Integer
		println j.class == Integer
		println j.class == int
		
		Byte b = 0
		println "b = $b"
		
		BigDecimal decimal = 0
		println "decimal = $decimal"
	}
	
	static void test1(){
		def s = ['a', 'b', 'c']
		println s.join(':')
	}
	
	static void test2(){
		GroovyBean bean = new GroovyBean()
		println bean.name
		println bean.@name
		println bean.getName()
		println bean.&getName()
	}
	
	static void test3(){
		JavaBean bean = new JavaBean()
		println bean.name
		println bean.@name
	}
	
	static void test4(){
		GroovyDomain domain = new GroovyDomain()
		println domain.getClass()
		println domain.getText()
		println domain.getCount()
//		println GroovyDomain.getField('text')
	}
	
	static void test5(){
//		GroovyBean bean = new GroovyBean()
		println GroovyTest.getField('name').type.name
	}
	
	static void test6(){
		JavaBean.printFields()
	}
	
	static void test7(){
		GroovyDomain.getMyClassName()
	}
	
	static void test8(){
		JavaDomain domain = new JavaDomain()
		println domain.getClass()
		println domain.getText()
		println domain.getCount()
		println domain.getName()
		println domain.getAge()
		println domain.getPrice()
	}
	
	static def test9(int count){
		if(count == 1){
			count
		}else{
			List list = []
			(1..count).each {
				list.add(it)
			}
			list
		}
	}
	
	private static void test10(String s){
		Map m = [key1:'value1', key2:'value2']
		m.keySet().each {
			println it
			println m.get(it)
		}
	}
	
	static void test11(){
		int i = 0
		assert i.class == int.class
	}
	
	static void test12(){
		JavaBean bean = new JavaBean()
		bean.name = "lee000"
		println bean.getName()
	}
	
	static void test13(){
		Class c = GroovyTest.class
//		def m = c.getDeclaredMethods().find {
////			println it
//			it.name.equals("test10")
//		}
		
		def m = c.getDeclaredMethod("test10", String)
		println m
	}
}
